﻿using System;

namespace UnitTesting.Fixturing
{
	class GuardNotResovledValue : IValueProvider
	{
		readonly IValueProvider _valueProvider;

		internal GuardNotResovledValue(IValueProvider valueProvider)
		{
			_valueProvider = Ensure.IsNotNull(() => valueProvider);
		}

		public object Create(Type type)
		{
			Ensure.IsNotNull(() => type);
			var result = _valueProvider.Create(type);
			if (result == NotResolved.Value)
			{
				throw new NotResolvedValueException(type);
			}
			return result;
		}
	}
}